package com.crime.crimemonitorclient;

import com.crimemonitor.library.CrimesSummary;

public class CrimeIndexChartViewFragment extends CrimeChartViewFragment
{
	private final Float	CRIME_INDEX_MIN	= 0.0f;
	private final Float	CRIME_INDEX_MAX	= 5.0f;

	@Override
	protected String getContentFromTemplate()
	{
		Float crimeIndex = this.getScaledCrimeIndex(mCrimesSummary
				.getCrimeIndex());
		final Float crimeIndex_Green_From = 0.0f, crimeIndex_Green_To = 2.0f, crimeIndex_Yellow_From = 2.0f, crimeIndex_Yellow_To = 4.0f, crimeIndex_Red_From = 4.0f, crimeIndex_Red_To = 5.0f;

		return mContentTemplate
				.replace("%height", mGraphHeightInDp.toString())
				.replace("%crimeIndexValue", crimeIndex.toString())
				.replace("%crimeIndex_Min", CRIME_INDEX_MIN.toString())
				.replace("%crimeIndex_Max", CRIME_INDEX_MAX.toString())
				.replace("%crimeIndex_Green_From",
						crimeIndex_Green_From.toString())
				.replace("%crimeIndex_Green_To", crimeIndex_Green_To.toString())
				.replace("%crimeIndex_Yellow_From",
						crimeIndex_Yellow_From.toString())
				.replace("%crimeIndex_Yellow_To",
						crimeIndex_Yellow_To.toString())
				.replace("%crimeIndex_Red_From", crimeIndex_Red_From.toString())
				.replace("%crimeIndex_Red_To", crimeIndex_Red_To.toString());
	}

	private float getScaledCrimeIndex(float crimeIndexNormalized)
	{
		return CRIME_INDEX_MIN + (CRIME_INDEX_MAX - CRIME_INDEX_MIN)
				* crimeIndexNormalized;
	}

	@Override
	protected String getTitle()
	{
		return this.getResources()
				.getString(R.string.crime_summary_index_label);
	}

}
